def p(n):
    for i in range(2,n):
        if n % i == 0:
            return False
    return True
    
x = int(input())

a = [i for i in range(2, x+1) if p(1)]

for i in range(2, x+1 ):
    if p(i):
        a.append(i)

m = 0
for i in a:
    if str(i) in str(x):
        m = i
print(m) 
